using Game;

namespace SCIENEW {
    /// <summary>
    /// 有燃烧切换、四个方向、提供动力作用的设备都继承自此
    /// </summary>
    public abstract class IlluminableDevice : FourDirectionalDevice{
        public int LightFrontSlot;
        public IlluminableDevice(string id, int frontSlot, int lightFrontSlot, int backSlot = 107, int sideSlot = 159, int upSlot = 107) : base(
            id,
            frontSlot,
            backSlot,
            sideSlot,
            upSlot
        ) {
            LightFrontSlot = lightFrontSlot;
        }

        public override int GetEmittedLightAmount(int value) => IsLight(value) ? 15 : 0;

        public override float GetHeat(int value) => IsLight(value) ? 0.66f : 0;

        protected static bool IsLight(int value) => DevicesUtils.GetInnerData(value) >> 2 == 1;

        public override bool IsFaceTransparent(SubsystemTerrain subsystemTerrain, int face, int value) => IsLight(value);

        public override bool IsTransparent_(int value) => IsLight(value);

        public override int GetShadowStrength(int value) => IsLight(value) ? -99 : base.GetShadowStrength(value);

        /// <summary>
        /// 只取机器特殊值前两位作为朝向，防止发光机器朝向错误
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        protected override int GetDirection(int value) => GetDirection_Static(value);

        public static int GetDirection_Static(int value) => DevicesUtils.GetInnerData(value) & 0b11;

        public override int GetFaceTextureSlot(int face, int value) {
            if (face is 4) return UpSlot;
            if (face is 5) return DownSlot;
            if (face == GetDirection(value)) return IsLight(value) ? LightFrontSlot : FrontSlot;
            if (face == CellFace.OppositeFace(GetDirection(value))) return BackSlot;
            return SideSlot;
        }
    }
}